from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType 


class Image(models.Model):
    user = models.ForeignKey(User)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey("content_type", "object_id")

    path = models.CharField(max_length=128)
    desc = models.CharField(max_length=128)
    size = models.PositiveIntegerField()
    ipaddr = models.IPAddressField(blank=True, null=True)
    timestamp = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ["-timestamp"]

    def __unicode__(self):
        return self.path

